#include "CLocation.h"

namespace csmodel
{
    ClassVisualTraits* CLocation::visualTraits = 0;

    //---------------------------------

    CLocation::CLocation( CEntity * anOwner ) : inherited ( 0, 1 )
    {
        if( anOwner )
            anOwner->Insert( this );
        Autosize( false );
        RegisterEntity( this );
        entities.insert( std::make_pair( 1, this ) );
    }

    //---------------------------------

    CLocation::~CLocation()
    {
        entities.clear();
        Nested().clear();
    }

    //---------------------------------

    void CLocation::Draw( IDrawEngine & di ) const
    {
        QRect b( Bounds() );
        di.Box( b );
    }

    //---------------------------------

    int CLocation::RegisterEntity( CEntity * entity )
    {
        int id = entity->Id();
        if( !id || ( entities.find( id ) != entities.end() ) )
            id = entities.rbegin()->first + 1;

        entities.insert( std::make_pair( id, entity ) );
        return id;
    }

    //---------------------------------

    void CLocation::UnRegisterEntity( CEntity * entity ) throw()
    {
        entities.erase( entity->Id() );
    }
}
